Electron-EE框架 在 MacOS 下 申请摄像头及麦克风权限踩坑指南 electron-egg
平台: c 在项目打包后,访问某一页面,调用了摄像头麦克风,devTool disconnected from the page …, 接着就白屏,想到可能是权限的 难题 步骤如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http:// .apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.cs.allow-jit</key> <true/> <key>com.apple.security.cs.allow-unsigned-executable-memory</key> <true/> <key>com.apple.security.cs.allow-dyld-environment-variables</key> <true/> <key>com.apple.security.device.audio-input</key> <true/> <key>com.apple.security.device.camera</key> <true/> </dict> </plist>
"entitlements": "entitlements. c.plist", "hardenedRuntime": true, "extendInfo": { "N icrophoneUsageDescription": "请允许本程序访问 无论兄弟们的麦克风", "NSCameraUsageDescription": "请允许本程序访问 无论兄弟们的摄像头" },
hardenedRuntime 这个属性,在 electron-builder 的 21.1.3 版本已经默认为 true ,而在 21.1.2 ~ 20.41.0 版本里,这个属性的默认值是 false。再往后的版本里没有这个属性。
打包之后在某些电脑出现白屏devTool disconnected from the page ...,后来查询得知
在 cOS 10.13 High Sierra 或更低版本上不需要用户授权,因此此 技巧总是返回 granted。 cOS 10.14 Mojave 或更高版本需要授权访问 麦克风 和 摄像头。 cOS 10.15 Catalina 或更高版本需要授权访问 屏幕。原文
高版本必须主动去询问